home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / usenet / volume2 / nethack / part05 < prev    next >
Encoding:
Internet Message Format  |  1987-07-29  |  54.7 KB

  1. Path: uunet!seismo!rutgers!ucla-cs!zen!ucbvax!decvax!tektronix!tekgen!tekred!games-request
  2. From: games-request@tekred.TEK.COM
  3. Newsgroups: comp.sources.games
  4. Subject: v02i005:  nethack - display oriented dungeons & dragons, Part05/16
  5. Message-ID: <1447@tekred.TEK.COM>
  6. Date: 28 Jul 87 17:45:19 GMT
  7. Sender: billr@tekred.TEK.COM
  8. Lines: 2245
  9. Approved: billr@tekred.TEK.COM
  10.  
  11. Submitted by: mike@genat.UUCP (Mike Stephenson)
  12. Comp.sources.games: Volume 2, Issue 5
  13. Archive-name: nethack/Part05
  14.  
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then unpack
  18. # it by saving it into a file and typing "sh file".  To overwrite existing
  19. # files, type "sh file -c".  You can also feed this as standard input via
  20. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  21. # will see the following message at the end:
  22. #        "End of archive 5 (of 16)."
  23. # Contents:  apply.c date.h mon.c trap.c
  24. # Wrapped by billr@tekred on Tue Jul 28 09:49:26 1987
  25. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  26. if test -f apply.c -a "${1}" != "-c" ; then 
  27.   echo shar: Will not over-write existing file \"apply.c\"
  28. else
  29. echo shar: Extracting \"apply.c\" \(13923 characters\)
  30. sed "s/^X//" >apply.c <<'END_OF_apply.c'
  31. X/*    SCCS Id: @(#)apply.c    1.3    87/07/14
  32. X/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  33. X/* apply.c - version 1.0.3 */
  34. X
  35. X#include    "hack.h"
  36. X#include    "edog.h"
  37. X#include    "mkroom.h"
  38. Xstatic struct monst *bchit();
  39. Xextern struct obj *addinv();
  40. Xextern struct trap *maketrap();
  41. Xextern int (*occupation)();
  42. Xextern char *occtxt;
  43. Xextern char quitchars[];
  44. Xextern char pl_character[];
  45. X
  46. X#ifdef KAA
  47. Xextern boolean unweapon;
  48. X#endif
  49. Xstatic use_camera(), use_ice_box(), use_whistle();
  50. Xstatic use_magic_whistle(), use_pick_axe();
  51. X#ifdef MARKER
  52. Xextern int dowrite();
  53. X#endif
  54. X
  55. Xdoapply() {
  56. X    register struct obj *obj;
  57. X    register int res = 1;
  58. X
  59. X    obj = getobj("(", "use or apply");
  60. X    if(!obj) return(0);
  61. X
  62. X    switch(obj->otyp){
  63. X    case EXPENSIVE_CAMERA:
  64. X        use_camera(obj); break;
  65. X    case ICE_BOX:
  66. X        use_ice_box(obj); break;
  67. X    case PICK_AXE:
  68. X        res = use_pick_axe(obj);
  69. X        break;
  70. X
  71. X    case MAGIC_WHISTLE:
  72. X        if(pl_character[0] == 'W' || u.ulevel > 9) {
  73. X            use_magic_whistle(obj);
  74. X            break;
  75. X        }
  76. X        /* fall into next case */
  77. X    case WHISTLE:
  78. X        use_whistle(obj);
  79. X        break;
  80. X#ifdef WALKIES
  81. X    case LEASH:
  82. X        use_leash(obj);
  83. X        break;
  84. X#endif
  85. X#ifdef MARKER
  86. X    case MAGIC_MARKER:
  87. X        dowrite(obj);
  88. X        break;
  89. X#endif
  90. X    case CAN_OPENER:
  91. X        if(!carrying(TIN)) {
  92. X            pline("You have no can to open.");
  93. X            goto xit;
  94. X        }
  95. X        pline("You cannot open a tin without eating its contents.");
  96. X        pline("In order to eat, use the 'e' command.");
  97. X        if(obj != uwep)
  98. X    pline("Opening the tin will be much easier if you wield the can-opener.");
  99. X        goto xit;
  100. X
  101. X#ifdef KAA
  102. X    case STETHOSCOPE:
  103. X        res = use_stethoscope(obj);
  104. X        break;
  105. X#endif
  106. X    default:
  107. X        pline("Sorry, I don't know how to use that.");
  108. X    xit:
  109. X        nomul(0);
  110. X        return(0);
  111. X    }
  112. X    nomul(0);
  113. X    return(res);
  114. X}
  115. X
  116. X/* ARGSUSED */
  117. Xstatic
  118. Xuse_camera(obj) /* register */ struct obj *obj; {
  119. Xregister struct monst *mtmp;
  120. X    if(!getdir(1)){        /* ask: in what direction? */
  121. X        flags.move = multi = 0;
  122. X        return;
  123. X    }
  124. X    if(u.uswallow) {
  125. X        pline("You take a picture of %s's stomach.", monnam(u.ustuck));
  126. X        return;
  127. X    }
  128. X    if(u.dz) {
  129. X        pline("You take a picture of the %s.",
  130. X            (u.dz > 0) ? "floor" : "ceiling");
  131. X        return;
  132. X    }
  133. X#ifdef KAA
  134. X    if(!u.dx && !u.dy && !u.dz) {
  135. X        if(!Blind) {
  136. X            pline("You are blinded by the flash!");
  137. X            Blind += rnd(25);
  138. X            seeoff(0);
  139. X        }
  140. X        return;
  141. X    }
  142. X#endif
  143. X    if(mtmp = bchit(u.dx, u.dy, COLNO, '!')) {
  144. X        if(mtmp->msleep){
  145. X            mtmp->msleep = 0;
  146. X            pline("The flash awakens %s.", monnam(mtmp)); /* a3 */
  147. X        } else
  148. X        if(mtmp->data->mlet != 'y')
  149. X        if(mtmp->mcansee || mtmp->mblinded){
  150. X            register int tmp = dist(mtmp->mx,mtmp->my);
  151. X            register int tmp2;
  152. X            if(cansee(mtmp->mx,mtmp->my))
  153. X              pline("%s is blinded by the flash!", Monnam(mtmp));
  154. X            setmangry(mtmp);
  155. X            if(tmp < 9 && !mtmp->isshk && rn2(4)) {
  156. X                mtmp->mflee = 1;
  157. X                if(rn2(4)) mtmp->mfleetim = rnd(100);
  158. X            }
  159. X            if(tmp < 3) mtmp->mcansee  = mtmp->mblinded = 0;
  160. X            else {
  161. X                tmp2 = mtmp->mblinded;
  162. X                tmp2 += rnd(1 + 50/tmp);
  163. X                if(tmp2 > 127) tmp2 = 127;
  164. X                mtmp->mblinded = tmp2;
  165. X                mtmp->mcansee = 0;
  166. X            }
  167. X        }
  168. X    }
  169. X}
  170. X
  171. X#ifdef KAA
  172. X/* Strictly speaking it makes no sense for usage of a stethoscope to
  173. X   not take any time; however, unless it did, the stethoscope would be
  174. X   almost useless. */
  175. Xstatic use_stethoscope(obj) register struct obj *obj; {
  176. Xregister struct monst *mtmp;
  177. Xregister struct rm *lev;
  178. Xregister int rx, ry;
  179. X    if(!freehand()) {
  180. X        pline("You have no free hand!");
  181. X        return(1);
  182. X    }
  183. X    if (!getdir(1)) {
  184. X        flags.move=multi=0;
  185. X        return(0);
  186. X    }
  187. X    if(u.dz < 0 || (u.dz && Levitation)) {
  188. X        pline("You can't reach the %s!", u.dz<0 ? "ceiling" : "floor");
  189. X        return(1);
  190. X    }
  191. X    if(u.dz) {
  192. X        pline("The floor seems healthy enough.");
  193. X        return(0);
  194. X    }
  195. X    if (Confusion) confdir();
  196. X    rx = u.ux + u.dx; ry = u.uy + u.dy;
  197. X    if(u.uswallow) {
  198. X        mstatusline(u.ustuck);
  199. X        return(0);
  200. X    }
  201. X    if(mtmp=m_at(rx,ry)) {
  202. X        mstatusline(mtmp);
  203. X        return(0);
  204. X    }
  205. X    if (!isok(rx,ry)) {
  206. X        pline("You hear the sounds at the end of the universe.");
  207. X        return(0);
  208. X    }
  209. X    lev = &levl[rx][ry];
  210. X    if(lev->typ == SDOOR) {
  211. X        pline("You hear a hollow sound!  This must be a secret door!");
  212. X        lev->typ = DOOR;
  213. X#ifdef DGK
  214. X        atl(rx, ry, symbol.door);
  215. X#else
  216. X        atl(rx, ry, DOOR_SYM);
  217. X#endif
  218. X        return(0);
  219. X    }
  220. X    if(lev->typ == SCORR) {
  221. X        pline("You hear a hollow sound!  This must be a secret passage!");
  222. X        lev->typ = CORR;
  223. X        atl(rx, ry, CORR_SYM);
  224. X        return(0);
  225. X    }
  226. X    pline("You hear nothing special.");
  227. X    return(0);
  228. X}
  229. X#endif    
  230. X    
  231. Xstatic
  232. Xstruct obj *current_ice_box;    /* a local variable of use_ice_box, to be
  233. X                used by its local procedures in/ck_ice_box */
  234. Xstatic
  235. Xin_ice_box(obj) register struct obj *obj; {
  236. X    if(obj == current_ice_box ||
  237. X        (Punished && (obj == uball || obj == uchain))){
  238. X        pline("You must be kidding.");
  239. X        return(0);
  240. X    }
  241. X    if(obj->owornmask & (W_ARMOR | W_RING)) {
  242. X        pline("You cannot refrigerate something you are wearing.");
  243. X        return(0);
  244. X    }
  245. X    if(obj->owt + current_ice_box->owt > 70) {
  246. X        pline("It won't fit.");
  247. X        return(1);    /* be careful! */
  248. X    }
  249. X    if(obj == uwep) {
  250. X        if(uwep->cursed) {
  251. X            pline("Your weapon is welded to your hand!");
  252. X            return(0);
  253. X        }
  254. X        setuwep((struct obj *) 0);
  255. X    }
  256. X    current_ice_box->owt += obj->owt;
  257. X    freeinv(obj);
  258. X    obj->o_cnt_id = current_ice_box->o_id;
  259. X    obj->nobj = fcobj;
  260. X    fcobj = obj;
  261. X    obj->age = moves - obj->age;    /* actual age */
  262. X    return(1);
  263. X}
  264. X
  265. Xstatic
  266. Xck_ice_box(obj) register struct obj *obj; {
  267. X    return(obj->o_cnt_id == current_ice_box->o_id);
  268. X}
  269. X
  270. Xstatic
  271. Xout_ice_box(obj) register struct obj *obj; {
  272. Xregister struct obj *otmp;
  273. X    if(obj == fcobj) fcobj = fcobj->nobj;
  274. X    else {
  275. X        for(otmp = fcobj; otmp->nobj != obj; otmp = otmp->nobj)
  276. X            if(!otmp->nobj) panic("out_ice_box");
  277. X        otmp->nobj = obj->nobj;
  278. X    }
  279. X    current_ice_box->owt -= obj->owt;
  280. X    obj->age = moves - obj->age;    /* simulated point of time */
  281. X    (void) addinv(obj);
  282. X}
  283. X
  284. Xstatic
  285. Xuse_ice_box(obj) register struct obj *obj; {
  286. Xregister int cnt = 0;
  287. Xregister struct obj *otmp;
  288. X    current_ice_box = obj;    /* for use by in/out_ice_box */
  289. X    for(otmp = fcobj; otmp; otmp = otmp->nobj)
  290. X        if(otmp->o_cnt_id == obj->o_id)
  291. X            cnt++;
  292. X    if(!cnt) pline("Your ice-box is empty.");
  293. X    else {
  294. X        pline("Do you want to take something out of the ice-box? [yn] ");
  295. X        if(readchar() == 'y')
  296. X        if(askchain(fcobj, (char *) 0, 0, out_ice_box, ck_ice_box, 0))
  297. X            return;
  298. X        pline("That was all. Do you wish to put something in? [yn] ");
  299. X        if(readchar() != 'y') return;
  300. X    }
  301. X    /* call getobj: 0: allow cnt; #: allow all types; %: expect food */
  302. X    otmp = getobj("0#%", "put in");
  303. X    if(!otmp || !in_ice_box(otmp))
  304. X        flags.move = multi = 0;
  305. X}
  306. X
  307. Xstatic
  308. Xstruct monst *
  309. Xbchit(ddx,ddy,range,sym) register int ddx,ddy,range; char sym; {
  310. X    register struct monst *mtmp = (struct monst *) 0;
  311. X    register int bchx = u.ux, bchy = u.uy;
  312. X
  313. X    if(sym) Tmp_at(-1, sym);    /* open call */
  314. X    while(range--) {
  315. X        bchx += ddx;
  316. X        bchy += ddy;
  317. X        if(mtmp = m_at(bchx,bchy))
  318. X            break;
  319. X        if(!ZAP_POS(levl[bchx][bchy].typ)) {
  320. X            bchx -= ddx;
  321. X            bchy -= ddy;
  322. X            break;
  323. X        }
  324. X        if(sym) Tmp_at(bchx, bchy);
  325. X    }
  326. X    if(sym) Tmp_at(-1, -1);
  327. X    return(mtmp);
  328. X}
  329. X
  330. X/* ARGSUSED */
  331. Xstatic
  332. Xuse_whistle(obj) struct obj *obj; {
  333. Xregister struct monst *mtmp = fmon;
  334. X    pline("You produce a high whistling sound.");
  335. X    while(mtmp) {
  336. X        if(dist(mtmp->mx,mtmp->my) < u.ulevel*20) {
  337. X            if(mtmp->msleep)
  338. X                mtmp->msleep = 0;
  339. X            if(mtmp->mtame)
  340. X                EDOG(mtmp)->whistletime = moves;
  341. X        }
  342. X        mtmp = mtmp->nmon;
  343. X    }
  344. X}
  345. X
  346. X/* ARGSUSED */
  347. Xstatic
  348. Xuse_magic_whistle(obj) struct obj *obj; {
  349. Xregister struct monst *mtmp = fmon;
  350. X    pline("You produce a strange whistling sound.");
  351. X    while(mtmp) {
  352. X        if(mtmp->mtame) mnexto(mtmp);
  353. X        mtmp = mtmp->nmon;
  354. X    }
  355. X}
  356. X
  357. X#ifdef WALKIES
  358. X/* ARGSUSED */
  359. Xstatic
  360. Xuse_leash(obj) struct obj *obj; {
  361. Xregister struct monst *mtmp = fmon;
  362. X
  363. X    while(mtmp && !mtmp->mleashed) mtmp = mtmp->nmon;
  364. X
  365. X    if(mtmp) {
  366. X
  367. X        if (next_to(mtmp))  {
  368. X
  369. X            mtmp->mleashed = 0;
  370. X            pline("You remove the leash from your %s.",
  371. X                 mtmp->data->mname);
  372. X        } else    pline("You must be next to your %s to unleash him.",
  373. X                 mtmp->data->mname);
  374. X    } else {
  375. X
  376. X        for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  377. X
  378. X        if(mtmp->mtame && next_to(mtmp)) {
  379. X
  380. X            pline("You slip the leash around your %s.", mtmp->data->mname);
  381. X            mtmp->mleashed = 1;
  382. X            if(mtmp->msleep)  mtmp->msleep = 0;
  383. X            return(0);
  384. X        }
  385. X        }
  386. X        pline("There's nothing here to put a leash on.");
  387. X    }
  388. X    return(0);
  389. X}
  390. X
  391. Xnext_to(mtmp) register struct monst *mtmp; {
  392. X
  393. X    return((abs(u.ux - mtmp->mx) <= 1) && (abs(u.uy - mtmp->my) <= 1));
  394. X}
  395. X#endif
  396. X
  397. Xstatic int dig_effort;    /* effort expended on current pos */
  398. Xstatic uchar dig_level;
  399. Xstatic coord dig_pos;
  400. Xstatic boolean dig_down;
  401. X
  402. Xstatic
  403. Xdig() {
  404. X    register struct rm *lev;
  405. X    register dpx = dig_pos.x, dpy = dig_pos.y;
  406. X
  407. X    /* perhaps a nymph stole his pick-axe while he was busy digging */
  408. X    /* or perhaps he teleported away */
  409. X    if(u.uswallow || !uwep || uwep->otyp != PICK_AXE ||
  410. X        dig_level != dlevel ||
  411. X        ((dig_down && (dpx != u.ux || dpy != u.uy)) ||
  412. X         (!dig_down && dist(dpx,dpy) > 2)))
  413. X        return(0);
  414. X
  415. X    dig_effort += 10 + abon() + uwep->spe + rn2(5);
  416. X    if(dig_down) {
  417. X        if(!xdnstair) {
  418. X            pline("The floor here seems too hard to dig in.");
  419. X            return(0);
  420. X        }
  421. X        if(dig_effort > 250) {
  422. X            dighole();
  423. X            return(0);    /* done with digging */
  424. X        }
  425. X        if(dig_effort > 50) {
  426. X            register struct trap *ttmp = t_at(dpx,dpy);
  427. X
  428. X            if(!ttmp) {
  429. X                ttmp = maketrap(dpx,dpy,PIT);
  430. X                ttmp->tseen = 1;
  431. X                pline("You have dug a pit.");
  432. X                u.utrap = rn1(4,2);
  433. X                u.utraptype = TT_PIT;
  434. X                return(0);
  435. X            }
  436. X        }
  437. X    } else
  438. X    if(dig_effort > 100) {
  439. X        register char *digtxt;
  440. X        register struct obj *obj;
  441. X
  442. X        lev = &levl[dpx][dpy];
  443. X        if(obj = sobj_at(ENORMOUS_ROCK, dpx, dpy)) {
  444. X            fracture_rock(obj);
  445. X            digtxt = "The rock falls apart.";
  446. X        } else if(!lev->typ || lev->typ == SCORR) {
  447. X            lev->typ = CORR;
  448. X            digtxt = "You succeeded in cutting away some rock.";
  449. X        } else if(lev->typ == HWALL || lev->typ == VWALL
  450. X                        || lev->typ == SDOOR) {
  451. X            lev->typ = xdnstair ? DOOR : ROOM;
  452. X            digtxt = "You just made an opening in the wall.";
  453. X        } else
  454. X          digtxt = "Now what exactly was it that you were digging in?";
  455. X        mnewsym(dpx, dpy);
  456. X        prl(dpx, dpy);
  457. X        pline(digtxt);        /* after mnewsym & prl */
  458. X        return(0);
  459. X    } else {
  460. X        if(IS_WALL(levl[dpx][dpy].typ)) {
  461. X            register int rno = inroom(dpx,dpy);
  462. X
  463. X            if(rno >= 0 && rooms[rno].rtype >= 8) {
  464. X              pline("This wall seems too hard to dig into.");
  465. X              return(0);
  466. X            }
  467. X        }
  468. X        pline("You hit the rock with all your might.");
  469. X    }
  470. X    return(1);
  471. X}
  472. X
  473. X/* When will hole be finished? Very rough indication used by shopkeeper. */
  474. Xholetime() {
  475. X    return( (occupation == dig) ? (250 - dig_effort)/20 : -1);
  476. X}
  477. X
  478. Xdighole()
  479. X{
  480. X    register struct trap *ttmp = t_at(u.ux, u.uy);
  481. X
  482. X    if(!xdnstair) {
  483. X        pline("The floor here seems too hard to dig in.");
  484. X    } else {
  485. X        if(ttmp)
  486. X            ttmp->ttyp = TRAPDOOR;
  487. X        else
  488. X            ttmp = maketrap(u.ux, u.uy, TRAPDOOR);
  489. X        ttmp->tseen = 1;
  490. X        pline("You've made a hole in the floor.");
  491. X        if(!u.ustuck && !Levitation) {            /* KAA */
  492. X            if(inshop())
  493. X                shopdig(1);
  494. X            pline("You fall through ...");
  495. X            if(u.utraptype == TT_PIT) {
  496. X                u.utrap = 0;
  497. X                u.utraptype = 0;
  498. X            }
  499. X            goto_level(dlevel+1, FALSE);
  500. X        }
  501. X    }
  502. X}
  503. X
  504. Xstatic
  505. Xuse_pick_axe(obj)
  506. Xstruct obj *obj;
  507. X{
  508. X    char dirsyms[12];
  509. X    extern char sdir[];
  510. X    register char *dsp = dirsyms, *sdp = sdir;
  511. X    register struct monst *mtmp;
  512. X    register struct rm *lev;
  513. X    register int rx, ry, res = 0;
  514. X
  515. X#ifndef FREEHAND
  516. X    /* edited by GAN 10/20/86 so that you can't apply the
  517. X     * pick-axe while wielding a cursed weapon
  518. X     */
  519. X    if(!freehand())  {
  520. X        pline("You have no free hand to dig with!");
  521. X        return(0);
  522. X    }
  523. X# ifdef KAA
  524. X    if(cantwield(u.usym)) {
  525. X        pline("You can't hold it strongly enough.");
  526. X        return(0);
  527. X    }
  528. X# endif
  529. X#else
  530. X    if(obj != uwep) {
  531. X        if(uwep && uwep->cursed) {
  532. X            /* Andreas Bormann - ihnp4!decvax!mcvax!unido!ab */
  533. X            pline("Since your weapon is welded to your hand,");
  534. X            pline("you cannot use that pick-axe.");
  535. X            return(0);
  536. X        }
  537. X# ifdef KAA
  538. X        if(cantwield(u.usym)) {
  539. X            pline("You can't hold it strongly enough.");
  540. X            return(0);
  541. X        }
  542. X        unweapon = TRUE;
  543. X# endif
  544. X        pline("You now wield %s.", doname(obj));
  545. X        setuwep(obj);
  546. X        res = 1;
  547. X    }
  548. X#endif
  549. X    while(*sdp) {
  550. X        (void) movecmd(*sdp);    /* sets u.dx and u.dy and u.dz */
  551. X        rx = u.ux + u.dx;
  552. X        ry = u.uy + u.dy;
  553. X        if(u.dz > 0 || (u.dz == 0 && isok(rx, ry) &&
  554. X            (IS_ROCK(levl[rx][ry].typ)
  555. X            || sobj_at(ENORMOUS_ROCK, rx, ry))))
  556. X            *dsp++ = *sdp;
  557. X        sdp++;
  558. X    }
  559. X    *dsp = 0;
  560. X    pline("In what direction do you want to dig? [%s] ", dirsyms);
  561. X    if(!getdir(0))        /* no txt */
  562. X        return(res);
  563. X    if(u.uswallow && attack(u.ustuck)) /* return(1) */;
  564. X    else
  565. X    if(u.dz < 0)
  566. X        pline("You cannot reach the ceiling.");
  567. X    else
  568. X#ifdef KAA
  569. X    if(!u.dx && !u.dy && !u.dz) {
  570. X        pline("You hit yourself with your own pick-axe.");
  571. X        losehp(rnd(2)+dbon(), "self-inflicted wound");
  572. X        flags.botl=1;
  573. X        return(1);
  574. X    }
  575. X#endif
  576. X    if(u.dz == 0) {
  577. X        if(Confusion)
  578. X            confdir();
  579. X        rx = u.ux + u.dx;
  580. X        ry = u.uy + u.dy;
  581. X        if((mtmp = m_at(rx, ry)) && attack(mtmp))
  582. X            return(1);
  583. X        if(!isok(rx, ry)) {
  584. X            pline("Clash!");
  585. X            return(1);
  586. X        }
  587. X        lev = &levl[rx][ry];
  588. X        if(lev->typ == DOOR)
  589. X            pline("Your %s against the door.",
  590. X                aobjnam(obj, "clang"));
  591. X        else if(!IS_ROCK(lev->typ)
  592. X             && !sobj_at(ENORMOUS_ROCK, rx, ry)) {
  593. X            /* ACCESSIBLE or POOL */
  594. X            pline("You swing your %s through thin air.",
  595. X                aobjnam(obj, (char *) 0));
  596. X        } else {
  597. X            if(dig_pos.x != rx || dig_pos.y != ry
  598. X                || dig_level != dlevel || dig_down) {
  599. X                dig_down = FALSE;
  600. X                dig_pos.x = rx;
  601. X                dig_pos.y = ry;
  602. X                dig_level = dlevel;
  603. X                dig_effort = 0;
  604. X                pline("You start digging.");
  605. X            } else
  606. X                pline("You continue digging.");
  607. X#ifdef DGKMOD
  608. X            set_occupation(dig, "digging", 0);
  609. X#else
  610. X            occupation = dig;
  611. X            occtxt = "digging";
  612. X#endif
  613. X        }
  614. X    } else if(Levitation) {
  615. X        pline("You cannot reach the floor.");
  616. X    } else {
  617. X        if(dig_pos.x != u.ux || dig_pos.y != u.uy
  618. X            || dig_level != dlevel || !dig_down) {
  619. X            dig_down = TRUE;
  620. X            dig_pos.x = u.ux;
  621. X            dig_pos.y = u.uy;
  622. X            dig_level = dlevel;
  623. X            dig_effort = 0;
  624. X            pline("You start digging in the floor.");
  625. X            if(inshop())
  626. X                shopdig(0);
  627. X        } else
  628. X            pline("You continue digging in the floor.");
  629. X#ifdef DGKMOD
  630. X        set_occupation(dig, "digging", 0);
  631. X#else
  632. X        occupation = dig;
  633. X        occtxt = "digging";
  634. X#endif
  635. X    }
  636. X    return(1);
  637. X}
  638. END_OF_apply.c
  639. if test 13923 -ne `wc -c <apply.c`; then
  640.     echo shar: \"apply.c\" unpacked with wrong size!
  641. fi
  642. # end of overwriting check
  643. fi
  644. if test -f date.h -a "${1}" != "-c" ; then 
  645.   echo shar: Will not over-write existing file \"date.h\"
  646. else
  647. echo shar: Extracting \"date.h\" \(88 characters\)
  648. sed "s/^X//" >date.h <<'END_OF_date.h'
  649. X/*    SCCS Id: @(#)date.h    1.3    87/07/14 */
  650. X
  651. Xchar datestring[] = "Fri Jun 26 11:49:16 1987";
  652. END_OF_date.h
  653. if test 88 -ne `wc -c <date.h`; then
  654.     echo shar: \"date.h\" unpacked with wrong size!
  655. fi
  656. # end of overwriting check
  657. fi
  658. if test -f mon.c -a "${1}" != "-c" ; then 
  659.   echo shar: Will not over-write existing file \"mon.c\"
  660. else
  661. echo shar: Extracting \"mon.c\" \(17706 characters\)
  662. sed "s/^X//" >mon.c <<'END_OF_mon.c'
  663. X/*    SCCS Id: @(#)mon.c    1.3    87/07/14
  664. X/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  665. X/* mon.c - version 1.0.3 */
  666. X
  667. X#include "hack.h"
  668. X#include "mfndpos.h"
  669. Xextern struct obj *mkobj_at();
  670. Xextern char *hcolor();
  671. X#ifdef KAA
  672. Xextern boolean    stoned;
  673. Xextern char mlarge[];
  674. X#endif
  675. X
  676. Xint warnlevel;        /* used by movemon and dochugw */
  677. Xlong lastwarntime;
  678. Xint lastwarnlev;
  679. Xchar    *warnings[] = {    "white", "pink", "red", "ruby", "purple", "black"  };
  680. X
  681. Xmovemon()
  682. X{
  683. X    register struct monst *mtmp;
  684. X    register int fr;
  685. X
  686. X    warnlevel = 0;
  687. X
  688. X    while(1) {
  689. X        /* find a monster that we haven't treated yet */
  690. X        /* note that mtmp or mtmp->nmon might get killed
  691. X           while mtmp moves, so we cannot just walk down the
  692. X           chain (even new monsters might get created!) */
  693. X        for(mtmp = fmon; mtmp; mtmp = mtmp->nmon)
  694. X            if(mtmp->mlstmv < moves) goto next_mon;
  695. X        /* treated all monsters */
  696. X        break;
  697. X
  698. X    next_mon:
  699. X        mtmp->mlstmv = moves;
  700. X
  701. X        /* most monsters drown in pools */
  702. X        { boolean inpool, iseel;
  703. X
  704. X          inpool = (levl[mtmp->mx][mtmp->my].typ == POOL);
  705. X          iseel = (mtmp->data->mlet == ';');
  706. X          if(inpool && !iseel) {
  707. X            if(cansee(mtmp->mx,mtmp->my))
  708. X                pline("%s drowns.", Monnam(mtmp));
  709. X            mondead(mtmp);
  710. X            continue;
  711. X          }
  712. X        /* but eels have a difficult time outside */
  713. X          if(iseel && !inpool) {
  714. X            if(mtmp->mhp > 1) mtmp->mhp--;
  715. X            mtmp->mflee = 1;
  716. X            mtmp->mfleetim += 2;
  717. X          }
  718. X        }
  719. X        if(mtmp->mblinded && !--mtmp->mblinded)
  720. X            mtmp->mcansee = 1;
  721. X        if(mtmp->mfleetim && !--mtmp->mfleetim)
  722. X            mtmp->mflee = 0;
  723. X        /* unwatched mimics and piercers may hide again  [MRS] */
  724. X        if(restrap(mtmp))    continue;
  725. X        if(mtmp->mimic) continue;
  726. X        if(mtmp->mspeed != MSLOW || !(moves%2)){
  727. X            /* continue if the monster died fighting */
  728. X            fr = -1;
  729. X            if(Conflict && cansee(mtmp->mx,mtmp->my)
  730. X                && (fr = fightm(mtmp)) == 2)
  731. X                continue;
  732. X            if(fr<0 && dochugw(mtmp))
  733. X                continue;
  734. X        }
  735. X        if(mtmp->mspeed == MFAST && dochugw(mtmp))
  736. X            continue;
  737. X    }
  738. X
  739. X    warnlevel -= u.ulevel;
  740. X    if(warnlevel >= SIZE(warnings))
  741. X        warnlevel = SIZE(warnings)-1;
  742. X    if(warnlevel >= 0)
  743. X    if(warnlevel > lastwarnlev || moves > lastwarntime + 5){
  744. X        register char *rr;
  745. X        switch(Warning & (LEFT_RING | RIGHT_RING)){
  746. X        case LEFT_RING:
  747. X        rr = "Your left ring glows";
  748. X        break;
  749. X        case RIGHT_RING:
  750. X        rr = "Your right ring glows";
  751. X        break;
  752. X        case LEFT_RING | RIGHT_RING:
  753. X        rr = "Both your rings glow";
  754. X        break;
  755. X        default:
  756. X        rr = "Your fingertips glow";
  757. X        break;
  758. X        }
  759. X        pline("%s %s!", rr, Hallucination ? hcolor() : warnings[warnlevel]);
  760. X        lastwarntime = moves;
  761. X        lastwarnlev = warnlevel;
  762. X    }
  763. X
  764. X    dmonsfree();    /* remove all dead monsters */
  765. X}
  766. X
  767. Xjustswld(mtmp,name)
  768. Xregister struct monst *mtmp;
  769. Xchar *name;
  770. X{
  771. X
  772. X    mtmp->mx = u.ux;
  773. X    mtmp->my = u.uy;
  774. X    u.ustuck = mtmp;
  775. X    pmon(mtmp);
  776. X    kludge("%s swallows you!",name);
  777. X    more();
  778. X    seeoff(1);
  779. X    u.uswallow = 1;
  780. X    u.uswldtim = 0;
  781. X    swallowed();
  782. X}
  783. X
  784. Xyouswld(mtmp,dam,die,name)
  785. Xregister struct monst *mtmp;
  786. Xregister dam,die;
  787. Xchar *name;
  788. X{
  789. X    if(mtmp != u.ustuck) return;
  790. X    kludge("%s digests you!",name);
  791. X    u.uhp -= dam;
  792. X    if(u.uswldtim++ >= die){    /* a3 */
  793. X        pline("It totally digests you!");
  794. X        u.uhp = -1;
  795. X    }
  796. X    if(u.uhp < 1) done_in_by(mtmp);
  797. X    /* flags.botlx = 1;        /* should we show status line ? */
  798. X}
  799. X
  800. X#ifdef ROCKMOLE
  801. Xmeatgold(mtmp) register struct monst *mtmp; {
  802. Xregister struct gold *gold;
  803. Xregister int pile;
  804. Xregister struct obj *otmp;
  805. X       /* Eats gold if it is there */
  806. X      while(gold = g_at(mtmp->mx, mtmp->my)){
  807. X          freegold(gold);
  808. X           /* Left behind a pile? */
  809. X           pile = rnd(25);
  810. X           if(pile < 3)
  811. X         mksobj_at(ROCK, mtmp->mx, mtmp->my);
  812. X          newsym(mtmp->mx, mtmp->my);
  813. X    }
  814. X       /* Eats armor if it is there */
  815. X       otmp = o_at(mtmp->mx,mtmp->my);
  816. X       if((otmp) && (otmp->otyp >= PLATE_MAIL) && (otmp->otyp <= RING_MAIL)){
  817. X          freeobj(otmp);
  818. X           /* Left behind a pile? */
  819. X           pile = rnd(25);
  820. X           if(pile < 3)
  821. X          mksobj_at(ROCK, mtmp->mx, mtmp->my);
  822. X          newsym(mtmp->mx, mtmp->my);
  823. X    }
  824. X}
  825. X#endif /* ROCKMOLE /**/
  826. X
  827. Xmpickgold(mtmp) register struct monst *mtmp; {
  828. Xregister struct gold *gold;
  829. Xregister struct obj *otmp;
  830. X    while(gold = g_at(mtmp->mx, mtmp->my)){
  831. X        mtmp->mgold += gold->amount;
  832. X        freegold(gold);
  833. X        if(levl[mtmp->mx][mtmp->my].scrsym == '$')
  834. X            newsym(mtmp->mx, mtmp->my);
  835. X    }
  836. X}
  837. X
  838. X/* Now includes giants which pick up enormous rocks.  KAA */
  839. Xmpickgems(mtmp) register struct monst *mtmp; {
  840. Xregister struct obj *otmp;
  841. X    for(otmp = fobj; otmp; otmp = otmp->nobj)
  842. X      if(otmp->olet ==
  843. X#ifdef KAA
  844. X               (mtmp->data->mlet=='9' ? ROCK_SYM : GEM_SYM))
  845. X#else
  846. X               GEM_SYM)
  847. X#endif
  848. X        if(otmp->ox == mtmp->mx && otmp->oy == mtmp->my)
  849. X          if(mtmp->data->mlet != 'u' || objects[otmp->otyp].g_val != 0){
  850. X        freeobj(otmp);
  851. X        mpickobj(mtmp, otmp);
  852. X#ifndef KAA
  853. X        if(levl[mtmp->mx][mtmp->my].scrsym == GEM_SYM)
  854. X#endif
  855. X            newsym(mtmp->mx, mtmp->my);    /* %% */
  856. X        return;    /* pick only one object */
  857. X          }
  858. X}
  859. X
  860. X/* return number of acceptable neighbour positions */
  861. Xmfndpos(mon,poss,info,flag)
  862. Xregister struct monst *mon;
  863. Xcoord poss[9];
  864. Xlong info[9], flag;
  865. X{
  866. X    register int x,y,nx,ny,cnt = 0,ntyp;
  867. X    register struct monst *mtmp;
  868. X    int nowtyp;
  869. X    boolean pool;
  870. X
  871. X    x = mon->mx;
  872. X    y = mon->my;
  873. X    nowtyp = levl[x][y].typ;
  874. X
  875. X    pool = (mon->data->mlet == ';');
  876. Xnexttry:    /* eels prefer the water, but if there is no water nearby,
  877. X           they will crawl over land */
  878. X    if(mon->mconf) {
  879. X        flag |= ALLOW_ALL;
  880. X        flag &= ~NOTONL;
  881. X    }
  882. X    for(nx = x-1; nx <= x+1; nx++) for(ny = y-1; ny <= y+1; ny++)
  883. X    if(nx != x || ny != y) if(isok(nx,ny))
  884. X#ifdef ROCKMOLE
  885. X    if(!IS_ROCK(ntyp = levl[nx][ny].typ) || (flag & ALLOW_WALL))
  886. X#else
  887. X    if(!IS_ROCK(ntyp = levl[nx][ny].typ))
  888. X#endif
  889. X    if(!(nx != x && ny != y && (nowtyp == DOOR || ntyp == DOOR)))
  890. X    if((ntyp == POOL) == pool) {
  891. X        info[cnt] = 0;
  892. X        if(nx == u.ux && ny == u.uy){
  893. X            if(!(flag & ALLOW_U)) continue;
  894. X            info[cnt] = ALLOW_U;
  895. X        } else if(mtmp = m_at(nx,ny)){
  896. X            if(!(flag & ALLOW_M)) continue;
  897. X            info[cnt] = ALLOW_M;
  898. X            if(mtmp->mtame){
  899. X                if(!(flag & ALLOW_TM)) continue;
  900. X                info[cnt] |= ALLOW_TM;
  901. X            }
  902. X        }
  903. X        if(sobj_at(CLOVE_OF_GARLIC, nx, ny)) {
  904. X            if(flag & NOGARLIC) continue;
  905. X            info[cnt] |= NOGARLIC;
  906. X        }
  907. X        if(sobj_at(SCR_SCARE_MONSTER, nx, ny) ||
  908. X           (!mon->mpeaceful && sengr_at("Elbereth", nx, ny))) {
  909. X            if(!(flag & ALLOW_SSM)) continue;
  910. X            info[cnt] |= ALLOW_SSM;
  911. X        }
  912. X        if(sobj_at(ENORMOUS_ROCK, nx, ny)) {
  913. X            if(!(flag & ALLOW_ROCK)) continue;
  914. X            info[cnt] |= ALLOW_ROCK;
  915. X        }
  916. X        if(!Invis && online(nx,ny)){
  917. X            if(flag & NOTONL) continue;
  918. X            info[cnt] |= NOTONL;
  919. X        }
  920. X        /* we cannot avoid traps of an unknown kind */
  921. X        { register struct trap *ttmp = t_at(nx, ny);
  922. X          register int tt;
  923. X            if(ttmp) {
  924. X                tt = 1 << ttmp->ttyp;
  925. X                /* below if added by GAN 02/06/87 to avoid
  926. X                 * traps out of range
  927. X                 */
  928. X                if(!(tt & ALLOW_TRAPS))  {
  929. X                    impossible("A monster looked at a very strange trap");
  930. X                    continue;
  931. X                }
  932. X                if(mon->mtrapseen & tt){
  933. X                    if(!(flag & tt)) continue;
  934. X                    info[cnt] |= tt;
  935. X                }
  936. X            }
  937. X        }
  938. X        poss[cnt].x = nx;
  939. X        poss[cnt].y = ny;
  940. X        cnt++;
  941. X    }
  942. X    if(!cnt && pool && nowtyp != POOL) {
  943. X        pool = FALSE;
  944. X        goto nexttry;
  945. X    }
  946. X    return(cnt);
  947. X}
  948. X
  949. Xdist(x,y) int x,y; {
  950. X    return((x-u.ux)*(x-u.ux) + (y-u.uy)*(y-u.uy));
  951. X}
  952. X
  953. Xpoisoned(string, pname)
  954. Xregister char *string, *pname;
  955. X{
  956. X    register i, plural;
  957. X
  958. X    plural = (string[strlen(string) - 1] == 's')? 1 : 0;
  959. X    if(Blind) {
  960. X        if (plural)    pline("They were poisoned.");
  961. X        else        pline("It was poisoned.");
  962. X    } else    {
  963. X        if (plural)    pline("The %s were poisoned!", string);
  964. X        else        pline("The %s was poisoned!", string);
  965. X    }
  966. X
  967. X    if(Poison_resistance) {
  968. X        pline("The poison doesn't seem to affect you.");
  969. X        return;
  970. X    }
  971. X    i = rn2(10);
  972. X    if(i == 0) {
  973. X        u.uhp = -1;
  974. X        pline("I am afraid the poison was deadly ...");
  975. X    } else if(i <= 5) {
  976. X        losestr(rn1(3,3));
  977. X    } else {
  978. X        losehp(rn1(10,6), pname);
  979. X    }
  980. X    if(u.uhp < 1) {
  981. X        killer = pname;
  982. X        done("died");
  983. X    }
  984. X}
  985. X
  986. Xmondead(mtmp)
  987. Xregister struct monst *mtmp;
  988. X{
  989. X    relobj(mtmp,1);
  990. X    unpmon(mtmp);
  991. X    relmon(mtmp);
  992. X    unstuck(mtmp);
  993. X#ifdef KOPS
  994. X       if(mtmp->data->mlet == 'K') {
  995. X       /* When a Kop dies, he probably comes back. */
  996. X       register int fate = rnd(3);
  997. X       if(fate == 1) {
  998. X         /* returns near the stairs */
  999. X         mkmon_at('K',xdnstair,ydnstair);
  1000. X       } else if(fate == 2) {
  1001. X         /* randomly */
  1002. X         mkmon_at('K',0,0);
  1003. X       }
  1004. X       }
  1005. X#endif
  1006. X    if(mtmp->isshk) shkdead(mtmp);
  1007. X    if(mtmp->isgd) gddead();
  1008. X#ifndef NOWORM
  1009. X    if(mtmp->wormno) wormdead(mtmp);
  1010. X#endif
  1011. X#ifdef HARD
  1012. X    if(mtmp->data->mlet == '1') wizdead(mtmp);
  1013. X#endif
  1014. X    monfree(mtmp);
  1015. X}
  1016. X
  1017. X/* called when monster is moved to larger structure */
  1018. Xreplmon(mtmp,mtmp2)
  1019. Xregister struct monst *mtmp, *mtmp2;
  1020. X{
  1021. X    relmon(mtmp);
  1022. X    monfree(mtmp);
  1023. X    mtmp2->nmon = fmon;
  1024. X    fmon = mtmp2;
  1025. X    if(u.ustuck == mtmp) u.ustuck = mtmp2;
  1026. X    if(mtmp2->isshk) replshk(mtmp,mtmp2);
  1027. X    if(mtmp2->isgd) replgd(mtmp,mtmp2);
  1028. X}
  1029. X
  1030. Xrelmon(mon)
  1031. Xregister struct monst *mon;
  1032. X{
  1033. X    register struct monst *mtmp;
  1034. X
  1035. X    if (fmon == 0)  panic ("relmon: no fmon available.");
  1036. X
  1037. X    if(mon == fmon) fmon = fmon->nmon;
  1038. X    else {
  1039. X        for(mtmp = fmon; mtmp->nmon != mon; mtmp = mtmp->nmon) ;
  1040. X        mtmp->nmon = mon->nmon;
  1041. X    }
  1042. X}
  1043. X
  1044. X/* we do not free monsters immediately, in order to have their name
  1045. X   available shortly after their demise */
  1046. Xstruct monst *fdmon;    /* chain of dead monsters, need not to be saved */
  1047. X
  1048. Xmonfree(mtmp) register struct monst *mtmp; {
  1049. X    mtmp->nmon = fdmon;
  1050. X    fdmon = mtmp;
  1051. X}
  1052. X
  1053. Xdmonsfree(){
  1054. Xregister struct monst *mtmp;
  1055. X    while(mtmp = fdmon){
  1056. X        fdmon = mtmp->nmon;
  1057. X        free((char *) mtmp);
  1058. X    }
  1059. X}
  1060. X
  1061. Xunstuck(mtmp)
  1062. Xregister struct monst *mtmp;
  1063. X{
  1064. X    if(u.ustuck == mtmp) {
  1065. X        if(u.uswallow){
  1066. X            u.ux = mtmp->mx;
  1067. X            u.uy = mtmp->my;
  1068. X            u.uswallow = 0;
  1069. X            setsee();
  1070. X            docrt();
  1071. X        }
  1072. X        u.ustuck = 0;
  1073. X    }
  1074. X}
  1075. X
  1076. Xkilled(mtmp)
  1077. Xregister struct monst *mtmp;
  1078. X{
  1079. X    xkilled(mtmp, 1);
  1080. X}
  1081. X
  1082. Xxkilled(mtmp, dest)
  1083. Xregister struct monst *mtmp;
  1084. Xint    dest;
  1085. X/* Dest=1, normal; dest=0, don't print message; dest=2, don't drop corpse
  1086. X   either; dest=3, message but no corpse */
  1087. X{
  1088. X#ifdef lint
  1089. X#define    NEW_SCORING
  1090. X#endif
  1091. X    register int tmp,tmp2,nk,x,y;
  1092. X    register struct permonst *mdat = mtmp->data;
  1093. X    extern long newuexp();
  1094. X
  1095. X    if(mtmp->cham) mdat = PM_CHAMELEON;
  1096. X    if (dest & 1) {
  1097. X        if(Blind) pline("You destroy it!");
  1098. X        else {
  1099. X        pline("You destroy %s!",
  1100. X            mtmp->mtame ? amonnam(mtmp, "poor") : monnam(mtmp));
  1101. X        }
  1102. X    }
  1103. X    if(u.umconf) {
  1104. X        if(!Blind)
  1105. X        {
  1106. X            pline("Your hands stop glowing %s.",
  1107. X            Hallucination ? hcolor() : "blue");
  1108. X        }
  1109. X        u.umconf = 0;
  1110. X    }
  1111. X
  1112. X    /* count killed monsters */
  1113. X#define    MAXMONNO    100
  1114. X    nk = 1;              /* in case we cannot find it in mons */
  1115. X    tmp = mdat - mons;    /* index in mons array (if not 'd', '@', ...) */
  1116. X    if(tmp >= 0 && tmp < CMNUM+2) {
  1117. X        extern char fut_geno[];
  1118. X        u.nr_killed[tmp]++;
  1119. X        if((nk = u.nr_killed[tmp]) > MAXMONNO &&
  1120. X        !index(fut_geno, mdat->mlet))
  1121. X            charcat(fut_geno,  mdat->mlet);
  1122. X    }
  1123. X
  1124. X    /* punish bad behaviour */
  1125. X    if(mdat->mlet == '@') {
  1126. X        HTelepat = 0;
  1127. X        u.uluck -= 2;
  1128. X    }
  1129. X    if(mtmp->mpeaceful || mtmp->mtame) u.uluck--;
  1130. X    if(mdat->mlet == 'u') u.uluck -= 5;
  1131. X    if((int)u.uluck < LUCKMIN) u.uluck = LUCKMIN;
  1132. X
  1133. X    /* give experience points */
  1134. X    tmp = 1 + mdat->mlevel * mdat->mlevel;
  1135. X    if(mdat->ac < 3) tmp += 2*(7 - mdat->ac);
  1136. X#ifdef KAA
  1137. X    if(index("AcsSDXaeRTVWU&In:P9", mdat->mlet))
  1138. X#else
  1139. X    if(index("AcsSDXaeRTVWU&In:P", mdat->mlet))
  1140. X#endif
  1141. X        tmp += 2*mdat->mlevel;
  1142. X    if(index("DeV&P",mdat->mlet)) tmp += (7*mdat->mlevel);
  1143. X    if(mdat->mlevel > 6) tmp += 50;
  1144. X    if(mdat->mlet == ';') tmp += 1000;
  1145. X
  1146. X#ifdef NEW_SCORING
  1147. X    /* ------- recent addition: make nr of points decrease
  1148. X           when this is not the first of this kind */
  1149. X    { int ul = u.ulevel;
  1150. X      int ml = mdat->mlevel;
  1151. X
  1152. X    if(ul < 14)    /* points are given based on present and future level */
  1153. X        for(tmp2 = 0; !tmp2 || ul + tmp2 <= ml; tmp2++)
  1154. X        if(u.uexp + 1 + (tmp + ((tmp2 <= 0) ? 0 : 4<<(tmp2-1)))/nk
  1155. X            >= 10*pow((unsigned)(ul-1)))
  1156. X            if(++ul == 14) break;
  1157. X
  1158. X    tmp2 = ml - ul -1;
  1159. X    tmp = (tmp + ((tmp2 < 0) ? 0 : 4<<tmp2))/nk;
  1160. X    if(!tmp) tmp = 1;
  1161. X    }
  1162. X    /* note: ul is not necessarily the future value of u.ulevel */
  1163. X    /* ------- end of recent valuation change ------- */
  1164. X#endif /* NEW_SCORING /**/
  1165. X
  1166. X    more_experienced(tmp,0);
  1167. X    flags.botl = 1;
  1168. X    while(u.ulevel < 14 && u.uexp >= newuexp()){
  1169. X        pline("Welcome to experience level %u.", ++u.ulevel);
  1170. X        tmp = rnd(10);
  1171. X        if(tmp < 3) tmp = rnd(10);
  1172. X        u.uhpmax += tmp;
  1173. X        u.uhp += tmp;
  1174. X#ifdef SPELLS
  1175. X        tmp = rnd(u.ulevel/2+1) + 1;    /* M. Stephenson */
  1176. X        u.uenmax += tmp;
  1177. X        u.uen += tmp;
  1178. X#endif
  1179. X        flags.botl = 1;
  1180. X    }
  1181. X
  1182. X    /* dispose of monster and make cadaver */
  1183. X    x = mtmp->mx;    y = mtmp->my;
  1184. X    mondead(mtmp);
  1185. X    tmp = mdat->mlet;
  1186. X    if(tmp == 'm') { /* he killed a minotaur, give him a wand of digging */
  1187. X            /* note: the dead minotaur will be on top of it! */
  1188. X        mksobj_at(WAN_DIGGING, x, y);
  1189. X        /* if(cansee(x,y)) atl(x,y,fobj->olet); */
  1190. X        stackobj(fobj);
  1191. X    } else
  1192. X#ifndef NOWORM
  1193. X    if(tmp == 'w') {
  1194. X        mksobj_at(WORM_TOOTH, x, y);
  1195. X        stackobj(fobj);
  1196. X    } else
  1197. X#endif
  1198. X#ifdef KAA
  1199. X    if(tmp == '&') (void) mkobj_at(0, x, y);
  1200. X    else
  1201. X    if(stoned == FALSE && (!letter(tmp) || (!index("9&1", tmp) && !rn2(3)))) tmp = 0;
  1202. X        if(dest & 2) {
  1203. X        newsym(x,y);
  1204. X        return;
  1205. X        }
  1206. X#else
  1207. X    if(!letter(tmp) || (!index("mw", tmp) && !rn2(3))) tmp = 0;
  1208. X#endif
  1209. X
  1210. X    if(ACCESSIBLE(levl[x][y].typ))    /* might be mimic in wall or dead eel*/
  1211. X        if(x != u.ux || y != u.uy) {  /* might be here after swallowed */
  1212. X#ifdef KAA
  1213. X        if(stoned) {
  1214. X            register char typetmp;
  1215. X            if(index(mlarge, tmp))    typetmp = ENORMOUS_ROCK;
  1216. X            else            typetmp = ROCK;
  1217. X            mksobj_at(typetmp, x, y);
  1218. X            if(cansee(x,y))
  1219. X                atl(x,y,Hallucination ? rndobjsym() :
  1220. X                objects[typetmp].oc_olet);
  1221. X        } else if(index("NTVm&w",mdat->mlet) || rn2(5)) {
  1222. X#else
  1223. X        if(index("NTVm&w",mdat->mlet) || rn2(5)) {
  1224. X#endif
  1225. X            register struct obj *obj2 = mkobj_at(tmp,x,y);
  1226. X            if(cansee(x,y))
  1227. X                atl(x, y, Hallucination ? rndobjsym() : obj2->olet);
  1228. X            stackobj(obj2);
  1229. X        }
  1230. X        }
  1231. X}
  1232. X
  1233. Xkludge(str,arg)
  1234. Xregister char *str,*arg;
  1235. X{
  1236. X    if(Blind) {
  1237. X        if(*str == '%') pline(str,"It");
  1238. X        else pline(str,"it");
  1239. X    } else pline(str,arg);
  1240. X}
  1241. X
  1242. Xrescham()    /* force all chameleons to become normal */
  1243. X{
  1244. X    register struct monst *mtmp;
  1245. X
  1246. X    for(mtmp = fmon; mtmp; mtmp = mtmp->nmon)
  1247. X        if(mtmp->cham) {
  1248. X            mtmp->cham = 0;
  1249. X            (void) newcham(mtmp, PM_CHAMELEON);
  1250. X        }
  1251. X}
  1252. X
  1253. X#ifdef DGKMOD
  1254. X/* Let the chameleons change again -dgk */
  1255. Xrestartcham()
  1256. X{
  1257. X    register struct monst *mtmp;
  1258. X
  1259. X    for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
  1260. X        if (mtmp->data->mlet == ':') 
  1261. X            mtmp->cham = 1;
  1262. X}
  1263. X#endif
  1264. X
  1265. Xnewcham(mtmp,mdat)    /* make a chameleon look like a new monster */
  1266. X            /* returns 1 if the monster actually changed */
  1267. Xregister struct monst *mtmp;
  1268. Xregister struct permonst *mdat;
  1269. X{
  1270. X    register mhp, hpn, hpd;
  1271. X
  1272. X    if(mdat == mtmp->data) return(0);    /* still the same monster */
  1273. X#ifndef NOWORM
  1274. X    if(mtmp->wormno) wormdead(mtmp);    /* throw tail away */
  1275. X#endif
  1276. X    hpn = mtmp->mhp;
  1277. X    hpd = (mtmp->data->mlevel)*8;    if(!hpd) hpd = 4;
  1278. X    mhp = (mdat->mlevel)*8;        if(!mhp) mhp = 4;
  1279. X
  1280. X    /* new hp: same fraction of max as before */
  1281. X    mtmp->mhp = (hpn*mhp)/hpd;
  1282. X    if (mhp > hpd && mtmp->mhp < hpn) mtmp->mhp = 127;
  1283. X/* Not totally foolproof.  A 2HD monster with 80 HP that changes into a 6HD
  1284. X   monster that really should have 240 and actually should have 127, the
  1285. X   maximum possible, will wind up having 113.  */
  1286. X    if (!mtmp->mhp) mtmp->mhp = 1;
  1287. X/* Unlikely but not impossible; a 1HD creature with 1HP that changes into a
  1288. X   0HD creature will require this statement */
  1289. X    mtmp->data = mdat;
  1290. X/* and the same for maximum hit points */
  1291. X    hpn = mtmp->mhpmax;
  1292. X    mtmp->mhpmax = (hpn*mhp)/hpd;
  1293. X    if (mhp > hpd && mtmp->mhpmax < hpn) mtmp->mhp = 127;
  1294. X    if (!mtmp->mhp) mtmp->mhp = 1;
  1295. X
  1296. X    mtmp->minvis = (mdat->mlet == 'I') ? 1 : 0;
  1297. X    /* only snakes and scorpions can hide under things -dgk */
  1298. X    /* also generated by GAN */
  1299. X    mtmp->mhide = (mdat->mlet == 'S' || mdat->mlet == 's') ? 1 : 0;
  1300. X    if (!mtmp->mhide) mtmp->mundetected = 0;
  1301. X#ifndef NOWORM
  1302. X    if(mdat->mlet == 'w' && getwn(mtmp)) initworm(mtmp);
  1303. X            /* perhaps we should clear mtmp->mtame here? */
  1304. X#endif
  1305. X    unpmon(mtmp);    /* necessary for 'I' and to force pmon */
  1306. X    pmon(mtmp);
  1307. X    return(1);
  1308. X}
  1309. X
  1310. Xmnexto(mtmp)    /* Make monster mtmp next to you (if possible) */
  1311. Xstruct monst *mtmp;
  1312. X{
  1313. X    extern coord enexto();
  1314. X    coord mm;
  1315. X    mm = enexto(u.ux, u.uy);
  1316. X    mtmp->mx = mm.x;
  1317. X    mtmp->my = mm.y;
  1318. X    pmon(mtmp);
  1319. X}
  1320. X
  1321. Xishuman(mtmp) register struct monst *mtmp; {
  1322. X    return(mtmp->data->mlet == '@');
  1323. X}
  1324. X
  1325. Xsetmangry(mtmp) register struct monst *mtmp; {
  1326. X    if(!mtmp->mpeaceful) return;
  1327. X    if(mtmp->mtame) return;
  1328. X    mtmp->mpeaceful = 0;
  1329. X    if(ishuman(mtmp)) pline("%s gets angry!", Monnam(mtmp));
  1330. X}
  1331. X
  1332. X/* not one hundred procent correct: now a snake may hide under an
  1333. X   invisible object */
  1334. Xcanseemon(mtmp)
  1335. Xregister struct monst *mtmp;
  1336. X{
  1337. X    return((!mtmp->minvis || See_invisible)
  1338. X        && (!mtmp->mhide || !o_at(mtmp->mx,mtmp->my))
  1339. X        && cansee(mtmp->mx, mtmp->my));
  1340. X}
  1341. X
  1342. Xdisturb(mtmp)        /* awaken monsters while in the same room.
  1343. X             * return a 1 if they have been woken.
  1344. X             */
  1345. Xregister struct monst *mtmp;
  1346. X{
  1347. X    /* wake up, or get out of here. */
  1348. X    /* ettins are hard to surprise */
  1349. X    /* Nymphs and Leprechauns do not easily wake up */
  1350. X    if(cansee(mtmp->mx,mtmp->my) &&
  1351. X        (!Stealth || (mtmp->data->mlet == 'e' && rn2(10))) &&
  1352. X        (!index("NL",mtmp->data->mlet) || !rn2(50)) &&
  1353. X        (Aggravate_monster || index("d1", mtmp->data->mlet)
  1354. X            || (!rn2(7) && !mtmp->mimic))) {
  1355. X        mtmp->msleep = 0;
  1356. X        return(1);
  1357. X    }
  1358. X    if(Hallucination) pmon(mtmp);
  1359. X    return(0);
  1360. X}
  1361. X
  1362. X#ifdef HARD
  1363. Xrestrap(mtmp)        /* unwatched mimics and piercers may hide again,
  1364. X             * if so, a 1 is returned.
  1365. X             */
  1366. Xregister struct monst *mtmp;
  1367. X{
  1368. X    if(mtmp->data->mlet == 'M' && !mtmp->mimic && !mtmp->cham
  1369. X       && !mtmp->mcan && !cansee(mtmp->mx, mtmp->my)
  1370. X       && !rn2(3)) {
  1371. X        mtmp->mimic = 1;
  1372. X        mtmp->mappearance = (levl[mtmp->mx][mtmp->my].typ == DOOR) ? DOOR_SYM : '$';
  1373. X        return(1);
  1374. X       }
  1375. X
  1376. X    if(mtmp->data->mlet == 'p' && !mtmp->cham
  1377. X       && !mtmp->mcan && !cansee(mtmp->mx, mtmp->my)
  1378. X       && !rn2(3))  {
  1379. X
  1380. X        if(levl[mtmp->mx][mtmp->my].typ == ROOM)  {
  1381. X
  1382. X            maketrap(mtmp->mx, mtmp->my, PIERC);
  1383. X            mondead(mtmp);
  1384. X            return(1);
  1385. X        }
  1386. X       }
  1387. X    return(0);
  1388. X}
  1389. X#endif
  1390. END_OF_mon.c
  1391. if test 17706 -ne `wc -c <mon.c`; then
  1392.     echo shar: \"mon.c\" unpacked with wrong size!
  1393. fi
  1394. # end of overwriting check
  1395. fi
  1396. if test -f trap.c -a "${1}" != "-c" ; then 
  1397.   echo shar: Will not over-write existing file \"trap.c\"
  1398. else
  1399. echo shar: Extracting \"trap.c\" \(19282 characters\)
  1400. sed "s/^X//" >trap.c <<'END_OF_trap.c'
  1401. X/*    SCCS Id: @(#)trap.c    1.3    87/07/14
  1402. X/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  1403. X/* trap.c - version 1.0.3 */
  1404. X
  1405. X#include    <stdio.h>
  1406. X#include    "hack.h"
  1407. X
  1408. Xextern struct monst *makemon();
  1409. X#ifdef KAA
  1410. Xextern char *Xmonnam();
  1411. Xextern char *nomovemsg;
  1412. X#endif
  1413. X
  1414. Xchar vowels[] = "aeiou";
  1415. X
  1416. Xchar *traps[] = {
  1417. X    "",
  1418. X    " bear trap",
  1419. X    "n arrow trap",
  1420. X    " dart trap",
  1421. X    " trapdoor",
  1422. X    " teleportation trap",
  1423. X    " pit",
  1424. X    " sleeping gas trap",
  1425. X    " piercer",
  1426. X    " mimic"
  1427. X#ifdef NEWTRAPS
  1428. X    ," magic trap"
  1429. X    ," squeaky board"
  1430. X#endif
  1431. X#ifdef SPIDERS
  1432. X    ," web"
  1433. X#endif
  1434. X#ifdef NEWCLASS
  1435. X    ," spiked pit",
  1436. X    " level teleporter"
  1437. X#endif
  1438. X#ifdef SPELLS
  1439. X    ," anti-magic field" 
  1440. X#endif
  1441. X#ifdef KAA
  1442. X    ," rust trap"
  1443. X#endif
  1444. X};
  1445. X
  1446. Xstruct trap *
  1447. Xmaketrap(x,y,typ)
  1448. Xregister x,y,typ;
  1449. X{
  1450. X    register struct trap *ttmp;
  1451. X
  1452. X    ttmp = newtrap();
  1453. X    ttmp->ttyp = typ;
  1454. X    ttmp->tseen = 0;
  1455. X    ttmp->once = 0;
  1456. X    ttmp->tx = x;
  1457. X    ttmp->ty = y;
  1458. X    ttmp->ntrap = ftrap;
  1459. X    ftrap = ttmp;
  1460. X    return(ttmp);
  1461. X}
  1462. X
  1463. Xdotrap(trap) register struct trap *trap; {
  1464. X    register int ttype = trap->ttyp;
  1465. X    register struct monst *mtmp;
  1466. X
  1467. X    nomul(0);
  1468. X    if(trap->tseen && !rn2(5) && !(ttype == PIT
  1469. X#ifdef NEWCLASS
  1470. X       || ttype == SPIKED_PIT
  1471. X#endif
  1472. X#ifdef SPELLS
  1473. X       || ttype == ANTI_MAGIC
  1474. X#endif
  1475. X        ))
  1476. X        pline("You escape a%s.", traps[ttype]);
  1477. X    else {
  1478. X        trap->tseen = 1;
  1479. X        switch(ttype) {
  1480. X        case SLP_GAS_TRAP:
  1481. X            pline("A cloud of gas puts you to sleep!");
  1482. X            nomul(-rnd(25));
  1483. X            break;
  1484. X        case BEAR_TRAP:
  1485. X            if(Levitation) {
  1486. X                pline("You float over a bear trap.");
  1487. X                break;
  1488. X            }
  1489. X            u.utrap = 4 + rn2(4);
  1490. X            u.utraptype = TT_BEARTRAP;
  1491. X            pline("A bear trap closes on your foot!");
  1492. X            if(u.usym=='o') pline("You howl in anger!");
  1493. X            break;
  1494. X        case PIERC:
  1495. X            deltrap(trap);
  1496. X            if(mtmp=makemon(PM_PIERCER,u.ux,u.uy)) {
  1497. X              pline("%s suddenly drops from the ceiling!", Xmonnam(mtmp));
  1498. X              if(uarmh)
  1499. X                pline("Its blow glances off your helmet.");
  1500. X              else
  1501. X                (void) thitu(3,d(4,6),"falling piercer");
  1502. X            }
  1503. X            break;
  1504. X        case ARROW_TRAP:
  1505. X            pline("An arrow shoots out at you!");
  1506. X            if(!thitu(8,rnd(6),"arrow")){
  1507. X                mksobj_at(ARROW, u.ux, u.uy);
  1508. X                fobj->quan = 1;
  1509. X            }
  1510. X            break;
  1511. X        case TRAPDOOR:
  1512. X            if(!xdnstair) {
  1513. Xpline("A trap door in the ceiling opens and a rock falls on your head!");
  1514. Xif(uarmh) pline("Fortunately, you are wearing a helmet!");
  1515. X                losehp(uarmh ? 2 : d(2,10),"falling rock");
  1516. X                mksobj_at(ROCK, u.ux, u.uy);
  1517. X                fobj->quan = 1;
  1518. X                stackobj(fobj);
  1519. X                if(Invisible) newsym(u.ux, u.uy);
  1520. X            } else {
  1521. X                register int newlevel = dlevel + 1;
  1522. X                while(!rn2(4) && newlevel < 29)
  1523. X                    newlevel++;
  1524. X                pline("A trap door opens up under you!");
  1525. X                if(Levitation || u.ustuck) {
  1526. X                pline("For some reason you don't fall in.");
  1527. X                    break;
  1528. X                }
  1529. X                fflush(stdout);
  1530. X                goto_level(newlevel, FALSE);
  1531. X            }
  1532. X            break;
  1533. X        case DART_TRAP:
  1534. X            pline("A little dart shoots out at you!");
  1535. X            if(thitu(7,rnd(3),"little dart")) {
  1536. X                if(!rn2(6))
  1537. X                poisoned("dart","poison dart");
  1538. X            } else {
  1539. X                mksobj_at(DART, u.ux, u.uy);
  1540. X                fobj->quan = 1;
  1541. X            }
  1542. X            break;
  1543. X        case TELEP_TRAP:
  1544. X            if(trap->once) {
  1545. X                deltrap(trap);
  1546. X                newsym(u.ux,u.uy);
  1547. X                vtele();
  1548. X            } else {
  1549. X                newsym(u.ux,u.uy);
  1550. X                tele();
  1551. X            }
  1552. X            break;
  1553. X#ifdef KAA
  1554. X        case RUST_TRAP:
  1555. X            switch (rn2(5)) {
  1556. X            case 0:
  1557. X                pline("A gush of water hits you on the head!");
  1558. X                if (uarmh) {
  1559. X                    if (uarmh->rustfree)
  1560. X                        pline("Your helmet is not affected!");
  1561. X                    else {
  1562. X                        pline("Your helmet rusts!");
  1563. X                        uarmh->spe--;
  1564. X                    }
  1565. X                }
  1566. X                break;
  1567. X            case 1:
  1568. X                pline("A gush of water hits your left arm!");
  1569. X                if (uarms) {
  1570. X                    pline("Your shield is not affected!");
  1571. X                    break;
  1572. X                }
  1573. X                if (uwep->otyp == TWO_HANDED_SWORD) goto two_hand;
  1574. X                /* Two goto statements in a row--aaarrrgggh! */
  1575. X        glovecheck: if(uarmg) pline("Your gloves are not affected!");
  1576. X                break;
  1577. X            case 2:
  1578. X                pline("A gush of water hits your right arm!");
  1579. X        two_hand: corrode_weapon();
  1580. X                goto glovecheck;
  1581. X            default:
  1582. X                pline("A gush of water hits you!");
  1583. X                if (uarm)
  1584. X                    if (uarm->rustfree ||
  1585. X                        uarm->otyp >= STUDDED_LEATHER_ARMOR) 
  1586. X                        pline("Your %s not affected!",
  1587. X                        aobjnam(uarm,"are"));
  1588. X                    else {
  1589. X                        pline("Your %s!",aobjnam(uarm,"corrode"));
  1590. X                        uarm->spe--;
  1591. X                    }
  1592. X            }
  1593. X            break;
  1594. X#endif
  1595. X        case PIT:
  1596. X            if (Levitation || index("EyBfk'&",u.usym)) {
  1597. X                pline("A pit opens up under you!");
  1598. X                pline("You don't fall in!");
  1599. X                break;
  1600. X            }
  1601. X            pline("You fall into a pit!");
  1602. X            u.utrap = rn1(6,2);
  1603. X            u.utraptype = TT_PIT;
  1604. X            losehp(rnd(6),"fall into a pit");
  1605. X            selftouch("Falling, you");
  1606. X            break;
  1607. X#ifdef NEWCLASS
  1608. X        case SPIKED_PIT:
  1609. X            if (Levitation || index("EyBfk'&",u.usym)) {
  1610. X                pline("A pit opens up under you!");
  1611. X                pline("You don't fall in!");
  1612. X                pline("There are spikes in that pit!!!");
  1613. X                break;
  1614. X            }
  1615. X            pline("You fall into a pit!");
  1616. X            pline("You land on a set of sharp iron spikes!");
  1617. X            u.utrap = rn1(6,2);
  1618. X            u.utraptype = TT_PIT;
  1619. X            losehp(rnd(10),"fall onto iron spikes");
  1620. X            if(!rn2(6)) poisoned("spikes","poison spikes");
  1621. X            selftouch("Falling, you");
  1622. X            break;
  1623. X        case LEVEL_TELEP:
  1624. X            if (!Blind)    pline("You are momentarily blinded by a flash of light");
  1625. X            else        pline("You are momentarily disoriented.");
  1626. X            deltrap(trap);
  1627. X            newsym(u.ux,u.uy);
  1628. X            level_tele();
  1629. X            break;
  1630. X#endif
  1631. X#ifdef SPELLS
  1632. X        case ANTI_MAGIC:
  1633. X            pline("You feel your magical energy drain away!");
  1634. X            u.uen -= (rnd(u.ulevel) + 1);
  1635. X            if(u.uen < 0)  {
  1636. X                u.uenmax += u.uen;
  1637. X                if(u.uenmax < 0) u.uenmax = 0;
  1638. X                u.uen = 0;
  1639. X            }
  1640. X            flags.botl = 1;
  1641. X            break;
  1642. X#endif
  1643. X#ifdef NEWTRAPS
  1644. X        case MGTRP:
  1645. X            /* A magic trap. */
  1646. X            domagictrap();
  1647. X            break;
  1648. X        case SQBRD: {
  1649. X#include      "edog.h"
  1650. X            register struct monst *mtmp = fmon;
  1651. X            /* Stepped on a squeaky board. */
  1652. X            pline("A board underfoot gives off a loud squeak!");
  1653. X            /* Wake up nearby monsters. */
  1654. X               while(mtmp) {
  1655. X             if(dist(mtmp->mx,mtmp->my) < u.ulevel*20) {
  1656. X                   if(mtmp->msleep)
  1657. X                       mtmp->msleep = 0;
  1658. X                   if(mtmp->mtame)
  1659. X                       EDOG(mtmp)->whistletime = moves;
  1660. X             }
  1661. X             mtmp = mtmp->nmon;
  1662. X               }
  1663. X        }
  1664. X            break;
  1665. X#endif
  1666. X#ifdef SPIDERS
  1667. X           case WEB:
  1668. X
  1669. X               /* Our luckless adventurer has stepped into a web. */
  1670. X
  1671. X               pline("You've stumbled into a spider web!");
  1672. X               u.utraptype = TT_WEB;
  1673. X
  1674. X               /* Time stuck in the web depends on your strength. */
  1675. X
  1676. X               if (u.ustr == 3) u.utrap = rn1(6,6);
  1677. X               else if (u.ustr < 6) u.utrap = rn1(6,4);
  1678. X               else if (u.ustr < 9) u.utrap = rn1(4,4);
  1679. X               else if (u.ustr < 12) u.utrap = rn1(4,2);
  1680. X               else if (u.ustr < 15) u.utrap = rn1(2,2);
  1681. X               else if (u.ustr < 18) u.utrap = rnd(2);
  1682. X               else if (u.ustr < 69) u.utrap = 1;
  1683. X               else {
  1684. X                   u.utrap = 0;
  1685. X                   pline("You tear through the web!");
  1686. X                   deltrap(trap);
  1687. X                }
  1688. X               break;
  1689. X#endif
  1690. X        default:
  1691. X            impossible("You hit a trap of type %u", trap->ttyp);
  1692. X        }
  1693. X    }
  1694. X}
  1695. X
  1696. Xmintrap(mtmp) register struct monst *mtmp; {
  1697. X    register struct trap *trap = t_at(mtmp->mx, mtmp->my);
  1698. X    register int wasintrap = mtmp->mtrapped;
  1699. X
  1700. X    if(!trap) {
  1701. X        mtmp->mtrapped = 0;    /* perhaps teleported? */
  1702. X    } else if(wasintrap) {
  1703. X        if(!rn2(40)) mtmp->mtrapped = 0;
  1704. X    } else {
  1705. X        register int tt = trap->ttyp;
  1706. X#ifdef DGK
  1707. X    /* A bug fix for dumb messages by ab@unido.
  1708. X     */
  1709. X        int in_sight = cansee(mtmp->mx,mtmp->my)
  1710. X               && (!mtmp->minvis || See_invisible);
  1711. X#else
  1712. X        int in_sight = cansee(mtmp->mx,mtmp->my);
  1713. X#endif
  1714. X        extern char mlarge[];
  1715. X
  1716. X        if(mtmp->mtrapseen & (1 << tt)) {
  1717. X        /* he has been in such a trap - perhaps he escapes */
  1718. X        if(rn2(4)) return(0);
  1719. X        }
  1720. X        mtmp->mtrapseen |= (1 << tt);
  1721. X        switch (tt) {
  1722. X        case BEAR_TRAP:
  1723. X            if(index(mlarge, mtmp->data->mlet)) {
  1724. X                if(in_sight)
  1725. X                  pline("%s is caught in a bear trap!",
  1726. X                    Monnam(mtmp));
  1727. X                else
  1728. X                  if(mtmp->data->mlet == 'o')
  1729. X                pline("You hear the roaring of an angry bear!");
  1730. X                mtmp->mtrapped = 1;
  1731. X            }
  1732. X            break;
  1733. X#ifdef KAA
  1734. X        case RUST_TRAP:
  1735. X            if(in_sight)
  1736. X                pline("A gush of water hits %s!",monnam(mtmp));
  1737. X            break;
  1738. X#endif
  1739. X        case PIT:
  1740. X#ifdef NEWCLASS
  1741. X        case SPIKED_PIT:
  1742. X#endif
  1743. X            /* there should be a mtmp/data -> floating */
  1744. X            if(!index("EywBIfk'& ", mtmp->data->mlet)) { /* ab */
  1745. X                mtmp->mtrapped = 1;
  1746. X                if(in_sight)
  1747. X                  pline("%s falls into a pit!", Monnam(mtmp));
  1748. X            }
  1749. X            break;
  1750. X        case SLP_GAS_TRAP:
  1751. X            if(!mtmp->msleep && !mtmp->mfroz) {
  1752. X                mtmp->msleep = 1;
  1753. X                if(in_sight)
  1754. X                  pline("%s suddenly falls asleep!",
  1755. X                    Monnam(mtmp));
  1756. X            }
  1757. X            break;
  1758. X        case TELEP_TRAP:
  1759. X#ifdef NEWCLASS
  1760. X        case LEVEL_TELEP:
  1761. X#endif
  1762. X            rloc(mtmp);
  1763. X            if(in_sight && !cansee(mtmp->mx,mtmp->my))
  1764. X                pline("%s suddenly disappears!",
  1765. X                    Monnam(mtmp));
  1766. X            break;
  1767. X        case ARROW_TRAP:
  1768. X            if(in_sight)
  1769. X                pline("%s is hit by an arrow!",    Monnam(mtmp));
  1770. X            mtmp->mhp -= 3;
  1771. X            break;
  1772. X        case DART_TRAP:
  1773. X            if(in_sight)
  1774. X                pline("%s is hit by a dart!", Monnam(mtmp));
  1775. X            mtmp->mhp -= 2;
  1776. X            /* not mondied here !! */
  1777. X            break;
  1778. X        case TRAPDOOR:
  1779. X            if(!xdnstair) {
  1780. X                mtmp->mhp -= 10;
  1781. X                if(in_sight)
  1782. Xpline("A trap door in the ceiling opens and a rock hits %s!", monnam(mtmp));
  1783. X                break;
  1784. X            }
  1785. X            if(!index("EywBIfk", mtmp->data->mlet)){
  1786. X                fall_down(mtmp);
  1787. X                if(in_sight)
  1788. X        pline("Suddenly, %s disappears out of sight.", monnam(mtmp));
  1789. X                return(2);    /* no longer on this level */
  1790. X            }
  1791. X            break;
  1792. X        case PIERC:
  1793. X            break;
  1794. X#ifdef NEWTRAPS
  1795. X        case MGTRP:
  1796. X            /* A magic trap.  Monsters immune. */
  1797. X            break;
  1798. X        case SQBRD: {
  1799. X            register struct monst *ztmp = fmon;
  1800. X            
  1801. X            if(index("EyBIfk", mtmp->data->mlet)) break;
  1802. X            /* Stepped on a squeaky board. */
  1803. X            if (in_sight)
  1804. X               pline("%s steps on a squeaky board.", Monnam(mtmp));
  1805. X            else
  1806. X               pline("You hear a distant squeak.");
  1807. X            /* Wake up nearby monsters. */
  1808. X               while(ztmp) {
  1809. X             if(dist2(mtmp->mx,mtmp->my,ztmp->mx,ztmp->my) < 40)
  1810. X                   if(ztmp->msleep) ztmp->msleep = 0;
  1811. X             ztmp = ztmp->nmon;
  1812. X               }
  1813. X            break;
  1814. X        }
  1815. X#endif
  1816. X#ifdef SPIDERS
  1817. X           case WEB:
  1818. X               /* Monster in a web. */
  1819. X            /* in_sight check and confused bear by Eric Backus */
  1820. X               if(mtmp->data->mlet != 's') {
  1821. X             if(in_sight)
  1822. X                pline("%s is caught in a web!", Monnam(mtmp));
  1823. X              else
  1824. X                if(mtmp->data->mlet == 'o')
  1825. X                  pline("You hear the roaring of a confused bear!");
  1826. X             mtmp->mtrapped = 1;
  1827. X               }
  1828. X              break;
  1829. X#endif
  1830. X#ifdef SPELLS
  1831. X        case ANTI_MAGIC:    break;
  1832. X#endif
  1833. X        default:
  1834. X            impossible("Some monster encountered a strange trap of type %d.",tt);
  1835. X        }
  1836. X    }
  1837. X    return(mtmp->mtrapped);
  1838. X}
  1839. X
  1840. Xselftouch(arg) char *arg; {
  1841. X    if(uwep && uwep->otyp == DEAD_COCKATRICE){
  1842. X        pline("%s touch the dead cockatrice.", arg);
  1843. X        pline("You turn to stone.");
  1844. X        pline("You die...");
  1845. X        killer = objects[uwep->otyp].oc_name;
  1846. X        done("died");
  1847. X    }
  1848. X}
  1849. X
  1850. Xfloat_up(){
  1851. X    if(u.utrap) {
  1852. X        if(u.utraptype == TT_PIT) {
  1853. X            u.utrap = 0;
  1854. X            pline("You float up, out of the pit!");
  1855. X        } else {
  1856. X            pline("You float up, only your leg is still stuck.");
  1857. X        }
  1858. X    } else
  1859. X        if (Hallucination)
  1860. X            pline("Oh wow!  You're floating in the air!");
  1861. X        else
  1862. X            pline("You start to float in the air!");
  1863. X}
  1864. X
  1865. Xfloat_down(){
  1866. X    register struct rm *tmpr;
  1867. X    register struct trap *trap;
  1868. X    
  1869. X    /* check for falling into pool - added by GAN 10/20/86 */
  1870. X    if(IS_POOL(levl[u.ux][u.uy].typ) && !Levitation)
  1871. X        drown();
  1872. X
  1873. X    pline("You float gently to the ground.");
  1874. X    if(trap = t_at(u.ux,u.uy))
  1875. X        switch(trap->ttyp) {
  1876. X        case PIERC:
  1877. X            break;
  1878. X        case TRAPDOOR:
  1879. X            if(!xdnstair || u.ustuck) break;
  1880. X            /* fall into next case */
  1881. X        default:
  1882. X            dotrap(trap);
  1883. X    }
  1884. X    pickup(1);
  1885. X}
  1886. X
  1887. X#include "mkroom.h"
  1888. X
  1889. Xvtele() {
  1890. X    register struct mkroom *croom;
  1891. X
  1892. X    for(croom = &rooms[0]; croom->hx >= 0; croom++)
  1893. X        if(croom->rtype == VAULT) {
  1894. X        register x,y;
  1895. X
  1896. X        x = rn2(2) ? croom->lx : croom->hx;
  1897. X        y = rn2(2) ? croom->ly : croom->hy;
  1898. X        if(teleok(x,y)) {
  1899. X            teleds(x,y);
  1900. X            return;
  1901. X        }
  1902. X        }
  1903. X    tele();
  1904. X}
  1905. X
  1906. Xtele() {
  1907. X    extern coord getpos();
  1908. X    coord cc;
  1909. X    register int nux,nuy;
  1910. X
  1911. X    if(Teleport_control) {
  1912. X#ifdef KAA
  1913. X        if (multi < 0 && (!nomovemsg ||
  1914. X                  !strncmp(nomovemsg,"You awake", 9) ||
  1915. X                  !strncmp(nomovemsg,"You regain con", 15) ||
  1916. X                  !strncmp(nomovemsg,"You are consci", 15)))
  1917. X        pline("Being unconscious, you cannot control your teleport.");
  1918. X        else {
  1919. X#endif
  1920. X    
  1921. X            pline("To what position do you want to be teleported?");
  1922. X            cc = getpos(1, "the desired position"); /* 1: force valid */
  1923. X            /* possible extensions: introduce a small error if
  1924. X               magic power is low; allow transfer to solid rock */
  1925. X            if(teleok(cc.x, cc.y)){
  1926. X            teleds(cc.x, cc.y);
  1927. X            return;
  1928. X            }
  1929. X            pline("Sorry ...");
  1930. X#ifdef KAA
  1931. X        }
  1932. X#endif
  1933. X    }
  1934. X    do {
  1935. X        nux = rnd(COLNO-1);
  1936. X        nuy = rn2(ROWNO);
  1937. X    } while(!teleok(nux, nuy));
  1938. X    teleds(nux, nuy);
  1939. X}
  1940. X
  1941. Xteleds(nux, nuy)
  1942. Xregister int nux,nuy;
  1943. X{
  1944. X    if(Punished) unplacebc();
  1945. X    unsee();
  1946. X    u.utrap = 0;
  1947. X    u.ustuck = 0;
  1948. X    u.ux = nux;
  1949. X    u.uy = nuy;
  1950. X    setsee();
  1951. X    if(Punished) placebc(1);
  1952. X    if(u.uswallow){
  1953. X        u.uswldtim = u.uswallow = 0;
  1954. X        docrt();
  1955. X    }
  1956. X    nomul(0);
  1957. X    if(IS_POOL(levl[nux][nuy].typ) && !Levitation)
  1958. X        drown();
  1959. X    (void) inshop();
  1960. X    pickup(1);
  1961. X    if(!Blind) read_engr_at(u.ux,u.uy);
  1962. X}
  1963. X
  1964. Xteleok(x,y) register int x,y; {    /* might throw him into a POOL
  1965. X                 * removed by GAN 10/20/86
  1966. X                 */
  1967. X#ifdef STUPID
  1968. X    boolean    tmp1, tmp2, tmp3;
  1969. X    tmp1 = isok(x,y) && !IS_ROCK(levl[x][y].typ) && !m_at(x,y);
  1970. X    tmp2 = !sobj_at(ENORMOUS_ROCK,x,y) && !t_at(x,y);
  1971. X    tmp3 = !(IS_POOL(levl[x][y].typ) && !Levitation);
  1972. X    return(tmp1 && tmp2 && tmp3);
  1973. X#else
  1974. X    return( isok(x,y) && !IS_ROCK(levl[x][y].typ) && !m_at(x,y) &&
  1975. X        !sobj_at(ENORMOUS_ROCK,x,y) && !t_at(x,y) &&
  1976. X        !(IS_POOL(levl[x][y].typ) && !Levitation)
  1977. X    );
  1978. X#endif
  1979. X    /* Note: gold is permitted (because of vaults) */
  1980. X}
  1981. X
  1982. Xdotele() {
  1983. X    extern char pl_character[];
  1984. X
  1985. X    if((!index("LNt",u.usym)) &&
  1986. X#ifdef WIZARD
  1987. X       !wizard &&
  1988. X#endif
  1989. X              (!Teleportation || u.ulevel < 6 ||
  1990. X            (pl_character[0] != 'W' && u.ulevel < 10))) {
  1991. X        pline("You are not able to teleport at will.");
  1992. X        return(0);
  1993. X    }
  1994. X    if(u.uhunger <= 100 || u.ustr < 6) {
  1995. X        pline("You miss the strength for a teleport spell.");
  1996. X#ifdef WIZARD
  1997. X        if(!wizard)
  1998. X#endif
  1999. X        return(1);
  2000. X    }
  2001. X    tele();
  2002. X    morehungry(100);
  2003. X    return(1);
  2004. X}
  2005. X
  2006. Xplacebc(attach) int attach; {
  2007. X    if(!uchain || !uball){
  2008. X        impossible("Where are your chain and ball??");
  2009. X        return;
  2010. X    }
  2011. X    uball->ox = uchain->ox = u.ux;
  2012. X    uball->oy = uchain->oy = u.uy;
  2013. X    if(attach){
  2014. X        uchain->nobj = fobj;
  2015. X        fobj = uchain;
  2016. X        if(!carried(uball)){
  2017. X            uball->nobj = fobj;
  2018. X            fobj = uball;
  2019. X        }
  2020. X    }
  2021. X}
  2022. X
  2023. Xunplacebc(){
  2024. X    if(!carried(uball)){
  2025. X        freeobj(uball);
  2026. X        unpobj(uball);
  2027. X    }
  2028. X    freeobj(uchain);
  2029. X    unpobj(uchain);
  2030. X}
  2031. X
  2032. Xlevel_tele() {
  2033. Xregister int newlevel;
  2034. X    if(Teleport_control) {
  2035. X        char buf[BUFSZ];
  2036. X
  2037. X        do {
  2038. X          pline("To what level do you want to teleport? [type a number] ");
  2039. X          getlin(buf);
  2040. X        } while(!digit(buf[0]) && (buf[0] != '-' || !digit(buf[1])));
  2041. X        newlevel = atoi(buf);
  2042. X    } else {
  2043. X#ifdef DGKMOD
  2044. X        newlevel  = rn2(5) ? 5 + rn2(20) : 30;
  2045. X#else
  2046. X        newlevel  = 5 + rn2(20);    /* 5 - 24 */
  2047. X#endif
  2048. X        if(dlevel == newlevel)
  2049. X        if(!xdnstair) newlevel--; else newlevel++;
  2050. X    }
  2051. X    if(newlevel >= 30) {
  2052. X        if(newlevel > MAXLEVEL) newlevel = MAXLEVEL;
  2053. X        pline("You arrive at the center of the earth ...");
  2054. X        pline("Unfortunately it is here that hell is located.");
  2055. X#ifdef DGK
  2056. X        fflush(stdout);
  2057. X#endif
  2058. X        if(Fire_resistance) {
  2059. X        pline("But the fire doesn't seem to harm you.");
  2060. X        } else {
  2061. X        pline("You burn to a crisp.");
  2062. X        pline("You die...");
  2063. X        dlevel = maxdlevel = newlevel;
  2064. X        killer = "visit to hell";
  2065. X        done("burned");
  2066. X        }
  2067. X    }
  2068. X    if(newlevel < 0) {
  2069. X        if(newlevel <= -10) {
  2070. X            pline("You arrive in heaven.");
  2071. X            pline("\"You are here a bit early, but we'll let you in.\"");
  2072. X            killer = "visit to heaven";
  2073. X            done("died");
  2074. X        }
  2075. X        newlevel = 0;
  2076. X        pline("You are now high above the clouds ...");
  2077. X        if(Levitation) {
  2078. X        pline("You float gently down to earth.");
  2079. X        done("escaped");
  2080. X        }
  2081. X        pline("Unfortunately, you don't know how to fly.");
  2082. X        pline("You fall down a few thousand feet and break your neck.");
  2083. X        pline("You die...");
  2084. X        dlevel = 0;
  2085. X        killer = "fall";
  2086. X        done("died");
  2087. X    }
  2088. X
  2089. X    goto_level(newlevel, FALSE); /* calls done("escaped") if newlevel==0 */
  2090. X}
  2091. X
  2092. X#ifdef NEWTRAPS
  2093. X
  2094. Xdomagictrap()
  2095. X{
  2096. X    register int fate = rnd(20);
  2097. X
  2098. X    /* What happened to the poor sucker? */
  2099. X
  2100. X    if (fate < 10) {
  2101. X
  2102. X      /* Most of the time, it creates some monsters. */
  2103. X      register int cnt = rnd(4);
  2104. X
  2105. X      /* below checks for blindness added by GAN 10/30/86 */
  2106. X      if (!Blind)  {
  2107. X        pline("You are momentarily blinded by a flash of light!");
  2108. X        Blind += rn1(5,10);
  2109. X        seeoff(0);
  2110. X      }  else
  2111. X        pline("You hear a deafening roar!");
  2112. X      while(cnt--)
  2113. X       (void) makemon((struct permonst *) 0, u.ux, u.uy);
  2114. X    }
  2115. X    else
  2116. X      switch (fate) {
  2117. X
  2118. X         case 10:
  2119. X         case 11:
  2120. X              /* sometimes nothing happens */
  2121. X            break;
  2122. X         case 12:
  2123. X              /* a flash of fire */
  2124. X              {
  2125. X            register int num;
  2126. X            
  2127. X            /* changed to be in conformance with
  2128. X             * SCR_FIRE by GAN 11/02/86
  2129. X             */
  2130. X            
  2131. X            pline("A tower of flame bursts from the floor!");
  2132. X            if(Fire_resistance)
  2133. X                pline("You are uninjured.");
  2134. X            else {
  2135. X                num = rnd(6);
  2136. X                u.uhpmax -= num;
  2137. X                losehp(num,"a burst of flame");
  2138. X                break;
  2139. X            }
  2140. X              }
  2141. X
  2142. X         /* odd feelings */
  2143. X         case 13:   pline("A shiver runs up and down your spine!");
  2144. X            break;
  2145. X         case 14:   pline("You hear distant howling.");
  2146. X            break;
  2147. X         case 15:   pline("You suddenly yearn for your distant homeland.");
  2148. X            break;
  2149. X         case 16:   pline("Your pack shakes violently!");
  2150. X            break;
  2151. X
  2152. X         /* very occasionally something nice happens. */
  2153. X
  2154. X         case 19:
  2155. X            /* tame nearby monsters */
  2156. X           {   register int i,j;
  2157. X               register boolean confused = (Confusion != 0);
  2158. X               register int bd = confused ? 5 : 1;
  2159. X               register struct monst *mtmp;
  2160. X
  2161. X               /* below pline added by GAN 10/30/86 */
  2162. X               pline("You feel charismatic.");
  2163. X               for(i = -bd; i <= bd; i++) for(j = -bd; j <= bd; j++)
  2164. X               if(mtmp = m_at(u.ux+i, u.uy+j))
  2165. X                   (void) tamedog(mtmp, (struct obj *) 0);
  2166. X               break;
  2167. X           }
  2168. X
  2169. X         case 20:
  2170. X            /* uncurse stuff */
  2171. X           {  register struct obj *obj;
  2172. X              register boolean confused = (Confusion != 0);
  2173. X
  2174. X            /* below plines added by GAN 10/30/86 */
  2175. X            if (confused)
  2176. X                if (Hallucination)
  2177. X                pline("You feel the power of the Force against you!");
  2178. X                else
  2179. X                pline("You feel like you need some help.");
  2180. X            else
  2181. X                if (Hallucination)
  2182. X                pline("You feel in touch with the Universal Oneness.");
  2183. X                else
  2184. X                pline("You feel like someone is helping you.");
  2185. X               for(obj = invent; obj ; obj = obj->nobj)
  2186. X                   if(obj->owornmask)
  2187. X                       obj->cursed = confused;
  2188. X               if(Punished && !confused) {
  2189. X                   Punished = 0;
  2190. X                   freeobj(uchain);
  2191. X                   unpobj(uchain);
  2192. X                   free((char *) uchain);
  2193. X                   uball->spe = 0;
  2194. X                   uball->owornmask &= ~W_BALL;
  2195. X                   uchain = uball = (struct obj *) 0;
  2196. X               }
  2197. X               break;
  2198. X           }
  2199. X         default: break;
  2200. X      }
  2201. X}
  2202. X
  2203. X#endif /* NEWTRAPS /**/
  2204. X
  2205. X
  2206. Xdrown()
  2207. X{
  2208. X    pline("You fall into a pool!");
  2209. X    pline("You can't swim!");
  2210. X    if(
  2211. X#ifdef WIZARD
  2212. X    wizard ||
  2213. X#endif
  2214. X    rn2(3) < u.uluck+2) {
  2215. X        /* most scrolls become unreadable */
  2216. X        register struct obj *obj;
  2217. X
  2218. X        for(obj = invent; obj; obj = obj->nobj)
  2219. X            if(obj->olet == SCROLL_SYM && rn2(12) > u.uluck)
  2220. X                obj->otyp = SCR_BLANK_PAPER;
  2221. X        /* we should perhaps merge these scrolls ? */
  2222. X
  2223. X        pline("You attempt a teleport spell.");    /* utcsri!carroll */
  2224. X        (void) dotele();
  2225. X        if(!IS_POOL(levl[u.ux][u.uy].typ)) return;
  2226. X    }
  2227. X    pline("You drown.");
  2228. X    pline("You die...");
  2229. X    killer = "pool of water";
  2230. X    done("drowned");
  2231. X}
  2232. END_OF_trap.c
  2233. if test 19282 -ne `wc -c <trap.c`; then
  2234.     echo shar: \"trap.c\" unpacked with wrong size!
  2235. fi
  2236. # end of overwriting check
  2237. fi
  2238. echo shar: End of archive 5 \(of 16\).
  2239. cp /dev/null ark5isdone
  2240. MISSING=""
  2241. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ; do
  2242.     if test ! -f ark${I}isdone ; then
  2243.     MISSING="${MISSING} ${I}"
  2244.     fi
  2245. done
  2246. if test "${MISSING}" = "" ; then
  2247.     echo You have unpacked all 16 archives.
  2248.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2249. else
  2250.     echo You still need to unpack the following archives:
  2251.     echo "        " ${MISSING}
  2252. fi
  2253. ##  End of shell archive.
  2254. exit 0
  2255.